<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const data = {
        name: 'foo',
        age: 18
    }

    for (let k in data) {
        let val = data[k]
        Object.defineProperty(data, k, {
            // 设置是否可枚举
            enumerable: true,
            // 是否可被修改和删除
            configurable: true,
            get() {
                console.log(`获取的值为：${val}`)
                return val
            },
            set(v) {
                console.log(`设置的值为：${v}`)
                val = v
            }
        })
    }
</script>
</body>
</html>
